<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算器示例</title>
    <link rel="stylesheet" href="../plugins/bootstrap-4.5.3-dist/css/bootstrap.min.css">
    <script src="../plugins/jquery/jquery-3.5.1.min.js"></script>
    <script src="../plugins/bootstrap-4.5.3-dist/js/bootstrap.min.js"></script>
    <script src="../plugins/vue/vue.min.js"></script>
</head>
<body>
    <div id="app">
        <div class="container" style="margin-top: 50px;width: 600px">
            <div class="row">
                <input v-model="message" class="col form-control" style="height: 50px"/>
            </div>
            <div class="row">
                <div class="col">
                    <button type="button" class="btn btn-info" @click="clickNum(1)">1</button>
                </div>
                <div class="col">
                    <button type="button" class="btn btn-info" @click="clickNum(2)">2</button>
                </div>
                <div class="col">
                    <button type="button" class="btn btn-info" @click="clickNum(3)">3</button>
                </div>
                <div class="col">
                    <button type="button" class="btn btn-warning" @click="addCal">+</button>
                </div>
            </div>
            <div class="row">
                <div class="col">
                    <button type="button" class="btn btn-info">4</button>
                </div>
                <div class="col">
                    <button type="button" class="btn btn-info">5</button>
                </div>
                <div class="col">
                    <button type="button" class="btn btn-info">6</button>
                </div>
                <div class="col">
                    <button type="button" class="btn btn-warning">-</button>
                </div>
            </div>
            <div class="row">
                <div class="col">
                    <button type="button" class="btn btn-info">7</button>
                </div>
                <div class="col">
                    <button type="button" class="btn btn-info">8</button>
                </div>
                <div class="col">
                    <button type="button" class="btn btn-info">9</button>
                </div>
                <div class="col">
                    <button type="button" class="btn btn-warning">*</button>
                </div>
            </div>
            <div class="row">
                <div class="col">
                    <button type="button" class="btn btn-danger" @click="resetCal">CE</button>
                </div>
                <div class="col">
                    <button type="button" class="btn btn-info">0</button>
                </div>
                <div class="col">
                    <button type="button" class="btn btn-success" @click="equalCal">=</button>
                </div>
                <div class="col">
                    <button type="button" class="btn btn-warning">/</button>
                </div>
            </div>
        </div>
    </div>


</body>

<script>
    new Vue({
        el:"#app",//xxx与第3步中定义的id的值保持一致
        data:{//用来定义变量的
            message :"",
            num1 : 0,//保存运算的第1个数字
            num2 : 0,//保存运算的第2个数字
            fuhao : 0, //统一做个规定，1表示+，2表示-，3表示*，4表示 /
            flagEqual: false,//这个变量用来标识，当前用户是否点击过 = 符号。如果点过，则再次点击数字时，是重新开始计数
        },
        methods:{//用来定义自定义界面事件的
            clickNum(num){//此方法用来统一管理点击所有数字后的事件操作
                if (this.flagEqual === true){
                    this.message = "";
                    //再将flagEqual这个变量改回原来的状态false
                    this.flagEqual = false;
                }
                this.message = this.message + num;
            },



            addCal(){
                //注意：这个this它是一个关键字，表示从当前vue中获取变量
                this.num1 = this.message;
                this.fuhao = 1;
                //赋值完成后，要将message变量的值清空
                this.message = "";
            },

            equalCal(){
                this.flagEqual = true;
                this.num2 = this.message;
                //再进行相应的运算
                if (this.fuhao == 1){//加法运算
                    this.message = parseInt(this.num1 )+ parseInt(this.num2);
                }else if (this.fuhao == 2){//减法运算

                }else if (this.fuhao == 3){//乘法运算

                }else if(this.fuhao == 4){//除法运算

                }
            },

            resetCal(){//清空操作
                this.message = "";
                this.num1 = 0;
                this.num2 = 0;

            }

        }

    })



</script>


<style>
    div{
        margin-top: 10px;
    }
    .btn{
        padding: 0;
        margin: 0;
        font-size: 4rem;
        font-weight: bolder;
        min-width: 100px;
        min-height: 100px;
        line-height: 100px;
        text-align: center;
    }
</style>
</html>